import numpy as np
import scipy

def dct2(x):
    return scipy.fftpack.dct(scipy.fftpack.dct(x.T, norm='ortho').T, norm='ortho')

# 二维离散余弦反变换
def idct2(x):
    return scipy.fftpack.idct(scipy.fftpack.idct(x.T, norm='ortho').T, norm='ortho')

# 生成一个8*8的矩阵
x = np.random.rand(8, 8)
# 将矩阵进行DCT变换
y = dct2(x)
# 将矩阵进行IDCT变换
z = idct2(y)
# 打印结果
print(x)
print(y)
print(z)